package com.impak.infoot.service.impl

import com.impak.infoot.service.ITeamService
import com.impak.infoot.domain.foot.Team
import com.impak.infoot.domain.foot.Season
import com.impak.infoot.domain.foot.Player
import com.impak.infoot.domain.foot.PlayerTeam
import com.impak.infoot.domain.foot.Match

/**
 * Implementation of the interface ITeamService
 * @author nzouabi
 *
 */
class TeamService implements ITeamService {
	
	def getTeam(teamId) {
		Team.get(teamId)
	}
	
	def getSeasonTeams(seasonId) {
		def season = Season.get(seasonId)
		season.teams
	}
	
	def getPlayerTeam(playerId, date) {
		def player = Player.get(playerId)
		def c = PlayerTeam.createCriteria()
		def results = c.get {
			and {
				eq("player", player)
				le("startDate",date)
				ge("endDate",date)
			}
			projections {
				property "team"
			}
		}
	}
	
	def getMatchTeams(matchId) {
		def match = Match.get(matchId)
		def teams = [match.localTeam, match.visitorTeam]
	}


}
